import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtQuick.Shapes 1.15

MainView {
    id: root
    width: 800
    height: 391
    GridLayout{ //root中放置一个行布局，布局中放置3个方块
        id: upgradeLayout
        anchors.centerIn: parent
        columnSpacing: 20 //间距
        rows: 1 //行数
        columns: 2 //列数

        Button
        {
            id:btnUDisk
            //x: 192
            //y: 74
            Layout.preferredWidth: 185
            Layout.preferredHeight: 85
            background: Rectangle{
                border.width: 0
                color: "#7584C2"
                    }

            text: qsTr("U盘")
            font.pixelSize: 25
            palette.buttonText: "white"
            onClicked: {
                if(upgradeLoader.visible)
                {
                    return;
                }
                upgradeLoader.visible=true;
                var res = mymodbus.uDiskUpgrade();
                if(res)
                {
                    upgradeSaveOKDialog.title=qsTr("下载完成，请重启完成升级！")
                    upgradeSaveOKDialog.open()
                    upgradeSaveOKDialog.accepted.connect(function() {
                                            //saveOKDialog.close()
                                            mymodbus.reBoot();
                                        })
                }
                else
                {
                    upgradeSaveOKDialog.title=qsTr("下载失败，请稍后重试！")
                    upgradeSaveOKDialog.open()
                    upgradeSaveOKDialog.accepted.connect(function() {
                                            saveOKDialog.close()
                                        })
                }
                upgradeLoader.visible=false;
            }
        }

        //Button
        //{
        //    id:btnEnglish
        //    x: 431
        //    y: 213
        //    Layout.preferredWidth: 185
        //    Layout.preferredHeight: 85
        //    background: Rectangle{
        //        border.width: 0
        //        color: "#7584C2"
        //            }

        //    text: "OTA"
        //    font.pixelSize: 25
        //    palette.buttonText: "white"
        //    onClicked: {
        ////          myLoader.visible=false;
        ////          myLoader.visible=true
        //        myLoader.source="OTAPanel.qml"
        //    }
        //}
    }
    Button
    {
        id:btnReturn
        x: 688
        y: 281
        //x: 675
        //y: 20
        width: 100
        height: 100
        background: Rectangle{
            border.width: 0
            color: "#B0B0D0"
                }

        text: qsTr("返回")
        font.pixelSize: 25
        palette.buttonText: "white"
        //Connections {
        //    target: btnReturn
            onClicked: {
                //rectangle.selectedView = 4
                bottomBar.selected=2
//                myLoader.visible=false;
//                myLoader.visible=true
                myLoader.source="FunctionPanel.qml"
            }
        //}
    }
    MyBuzyIndicator{
        anchors.centerIn: parent
        id: upgradeLoader
        visible:false
        z:101
    }
    Dialog {
        anchors.centerIn: parent
        id: upgradeSaveOKDialog
        //title: "提示"
        standardButtons: Dialog.Ok
        //title:qsTr("保存成功！")
        modal: true
        closePolicy: "CloseOnEscape"
 //       onAccepted: {
 //           normalParaSaveOKDialog.close()
 //           rectangle.selectedView = 0;
 //           bottomBar.selected = 0;
 //       }
        z:100
        //onRejected: console.log("Cancel clicked")
    }
}


